<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // javascript提供了三种方法改变函数内this指向 call() apply() bind()
        // 1. call()
        var o = {
            uname: "andy"
        };

        function fn(a, b) {
            console.log(this);
            console.log(a + b);
        }
        fn.call(o, 1, 2);
        // call可以调用函数和改变函数内的this指向
        // call的主要作用可以实现继承
        function Father(uname, age, sex) {
            this.uname = uname;
            this.age = age;
            this.sex = sex;
        };

        function Son(uname, age, sex, add) {
            Father.call(this, uname, age, sex);
            this.add = add;
        };
        var son = new Son("刘德华", 18, "男", "长沙");
        console.log(son);
    </script>
</body>

</html>